//
//  BCOrderHistoryAppealInputCollectionViewCell.m
//  BangcaiBuy
//
//  Created by Liang Zhang on 16/7/4.
//  Copyright © 2016年 BCB. All rights reserved.
//

#import "BCOrderHistoryAppealInputCollectionViewCell.h"

@interface BCOrderHistoryAppealInputCollectionViewCell () <UITextViewDelegate>

@end

@implementation BCOrderHistoryAppealInputCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    _appealInputView.layer.cornerRadius = 5.f;
    _appealInputView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    _appealInputView.layer.borderWidth = 1.f;
    _appealTextView.delegate = self;
    UIView *accessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40.f)];
    accessoryView.backgroundColor = [UIColor whiteColor];
    UIButton *keyboardTipButton = [UIButton buttonWithType:UIButtonTypeCustom];
    keyboardTipButton.frame = accessoryView.bounds;
    keyboardTipButton.titleLabel.font = [UIFont systemFontOfSize:13];
    [keyboardTipButton setTitleColor:BangcaiGreen forState:UIControlStateNormal];
    [keyboardTipButton setTitle:@"点击完成输入" forState:UIControlStateNormal];
    [keyboardTipButton addTarget:self action:@selector(inputDoneAction) forControlEvents:UIControlEventTouchUpInside];
    [accessoryView addSubview:keyboardTipButton];
    _appealTextView.inputAccessoryView = accessoryView;
}

+ (instancetype)cellWithCollectionView:(UICollectionView *)collectionView {
    static NSString *ID = @"HistoryAppealInputCollectionViewCell";
    UINib *nib = [UINib nibWithNibName:@"BCOrderHistoryAppealInputCollectionViewCell" bundle: [NSBundle mainBundle]];
    [collectionView registerNib:nib forCellWithReuseIdentifier:ID];
    BCOrderHistoryAppealInputCollectionViewCell *cell = [[BCOrderHistoryAppealInputCollectionViewCell alloc] init];
    return cell;
}

-(void)inputDoneAction {
    [_appealTextView resignFirstResponder];
    if ([_appealTextView.text isEqualToString:@""]) {
        _placeholderLable.hidden = NO;
    }
}

-(void)textViewDidBeginEditing:(UITextView *)textView {
    _placeholderLable.hidden = YES;
}

-(void)textViewDidEndEditing:(UITextView *)textView {
    [textView resignFirstResponder];
    if ([textView.text isEqualToString:@""]) {
        _placeholderLable.hidden = NO;
    }
}

@end
